package com.company.algo.stack;

import java.util.Arrays;
import java.util.Deque;
import java.util.LinkedList;
//使用栈完成反转相关的操作
public class Demo {
    public String solution(String line){
        String[] words = line.split(",");
        StringBuilder begin = new StringBuilder();
        for(int i = words.length - 1; i>=0 ;i--){
            begin.append(words[i]);
            if(i != 0){
                begin.append(",");
            }
        }
        return begin.toString();
    }
    public String solution2(String line){
        Deque<String> st = new LinkedList<>(Arrays.asList(line.split(",")));
        StringBuilder begin = new StringBuilder();
        while (!st.isEmpty()){
            begin.append(st.poll());
            if (begin.length()<line.length()-1){
                begin.append(",");
            }
        }
        return begin.toString();
    }

    public static void main(String[] args) {
        Demo demo = new Demo();
        String line = "hello, i am chenzhi, 肉蛋葱鸡";
        System.out.println(demo.solution2(line));
    }
}
